import java.util.*;

public class FruitPrice {
    // 水果价格表
    private static final Map<String, Double> PRICES = new HashMap<>();
    private static final Map<String, Double> PROMOTION_PRICES = new HashMap<>();

    static {
        PRICES.put("apple", 8.0);  // 苹果
        PRICES.put("strawberry", 13.0); // 草莓
        PRICES.put("mango", 20.0); // 芒果

        // 促销价格：草莓打8折
        PROMOTION_PRICES.put("strawberry", 13.0 * 0.8);
    }

    // 计算顾客A的账单（只有苹果和草莓） 两种
    public static double calcTwoFruits(Map<String, Integer> quantities) {
        return calculateBill(quantities, PRICES);
    }

    // 计算顾客B的账单（有苹果、草莓和芒果） 三种
    public static double calcThreeFruits(Map<String, Integer> quantities) {
        return calculateBill(quantities, PRICES);
    }

    // 计算顾客C的账单（有促销的草莓） 三种，草莓打折
    public static double calcProStawberry(Map<String, Integer> quantities) {
        return calculateBill(quantities, PROMOTION_PRICES);
    }

    // 计算顾客D的账单（有促销和满减）
    public static double calcProAndDiscount(Map<String, Integer> quantities) {
        double total = calculateBill(quantities, PROMOTION_PRICES);
        if (total >= 100) {
            total -= 10;
        }
        return total;
    }

    // 通用计算逻辑
    private static double calculateBill(Map<String, Integer> quantities, Map<String, Double> prices) {
        double total = 0.0;
        for (Map.Entry<String, Integer> entry : quantities.entrySet()) {
            String fruit = entry.getKey();
            int quantity = entry.getValue();
            if (prices.containsKey(fruit)) {
                total += prices.get(fruit) * quantity;
            }
        }
        return total;
    }

    public static void main(String[] args) {
        // 测试用例
        Map<String, Integer> testTwoFruits = new HashMap<>();
        testTwoFruits.put("apple", 2);
        testTwoFruits.put("strawberry", 3);
        System.out.println("Customer A+B: " + calcTwoFruits(testTwoFruits)); // 8*2 + 13*3 = 55

        Map<String, Integer> testThreeFruits = new HashMap<>();
        testThreeFruits.put("apple", 1);
        testThreeFruits.put("strawberry", 2);
        testThreeFruits.put("mango", 1);
        System.out.println("Customer A + B + C: " + calcThreeFruits(testThreeFruits)); // 8*1 + 13*2 + 20*1 = 54

        Map<String, Integer> testProFruits = new HashMap<>();
        testProFruits.put("apple", 3);
        testProFruits.put("strawberry", 4);
        testProFruits.put("mango", 2);
        System.out.println("Customer Pro A + B + C: " + calcProStawberry(testProFruits)); // 8*3 + 10.4*4 + 20*2 = 81.6

        Map<String, Integer> testD = new HashMap<>();
        testD.put("apple", 5);
        testD.put("strawberry", 6);
        testD.put("mango", 3);
        double totalD = calcProAndDiscount(testD); // 8*5 + 10.4*6 + 20*3 = 142.4 - 10 = 132.4
        System.out.println("Customer D: " + totalD);
    }
}
